<?php
declare (strict_types=1);

namespace app\service;

use app\db\BigDb;
use think\facade\Log;

class BigService
{
    protected $bigDb;

    public function __construct(BigDb $bigDb)
    {
        $this->bigDb = $bigDb;
    }


    //合并接口
    public function bigshow($uniacid, $id, $themeid)
    {
        $arr = $this->bigDb->comDbfindtheme($uniacid, $id); //含有  7访客 12345
        $fanssum = 0;
        if (!is_null($arr['vdata'])) {
            $fanssum = $arr['vdata']['fanssum'];
        }

        $zhuncusarr = $this->zhuncus($uniacid, $themeid);
        $newarr = $this->newoldcus($uniacid, $themeid, '新');
        $oldarr = $this->newoldcus($uniacid, $themeid, '老');


        //6准客
        $zhuncus = $zhuncusarr['vdata']['num']; //是num
        $arr['vdata']['zhuncus'] = $zhuncus;
        //8新
        $new = $newarr['vdata']['num'];
        $arr['vdata']['newnum'] = $new;
        //9老
        $old = $oldarr['vdata']['num'];
        $arr['vdata']['oldnum'] = $old;

        //新需求
        //$arr['vdata']['paynum']= $new+$old;
        $xtarr = $this->bigDb->findHomeOrderNum($uniacid, $themeid); //含有  7访客 12345
        //等会上
        //$arr['vdata']['paynum']=$xtarr['vdata']->newpaynum;

        //$arr['vdata']['paynum']= $arr['vdata'];
        //10已支付
        $payonarr = $this->payon($uniacid, $themeid);
        $payon = $payonarr['vdata']['num'];
        $arr['vdata']['payon'] = $payon;

        //11 计算未支付
        //首先判断访客是否大于0
        $payoff = 0;
        if ($fanssum > 0 &&  $fanssum >$payon ) {
            $payoff = $fanssum- $payon;
        }
        $arr['vdata']['payoff'] = $payoff;
        //2025 3 18 要改个东西 黄皓宇 经理反应的业务问题
        // 居然是是平台 和 订单id  没有活动id?

        return $arr;
    }

    //  $arr = $this->bigDb->findHomeOrderNum($uniacid, $themeid); //从订单里找 就应该是count
    public function findHomeOrderNum($uniacid, $id, $themeid){
        $arr = $this->bigDb->findHomeOrderNum($uniacid, $themeid); //含有  7访客 12345
        return $arr;
    }

    /**
     * 执行服务
     *
     * @return mixed
     */
    public function zhuncus($uniacid, $themeid)
    {
        return $this->bigDb->zhuncus($uniacid, $themeid);
    }


    //访客
    public function findone002($uniacid, $id)
    {
        return $this->bigDb->findone002($uniacid, $id);
    }

    //访客
    //todo 重构
    public function fanssum($uniacid, $id)
    {
        //return $this->bigDb->fanssum($uniacid,$id);
        return $this->bigDb->fanssum($uniacid, $id);
    }

    //处理未支付 payoff
    public function payoff($uniacid, $themeid, $id)
    {
        //return $this->bigDb->fanssum($uniacid,$id);
        $arr = $this->fanssum($uniacid, $id); //不一定要访问DB
        if (!is_null($arr['vdata'])) {
            //有访客
            $paramarr = $this->payon($uniacid, $themeid);
            $data = $paramarr['data'][0];
            $arr['numobj'] = $data; //已支付有10个
            $arr['已支付人数'] = $data['num'];
            $arr['访客数'] = $arr['vdata']['fanssum'];
            $arr['未支付人数'] = $arr['vdata']['fanssum'] - $data['num'];
            $arr['vdata']['payoff'] = $arr['vdata']['fanssum'] - $data['num'];
        }
        //
        return $arr;
    }


    public function findone003($uniacid, $id)
    {
        return $this->bigDb->fanssum($uniacid, $id);
    }


    //activitietitle
    public function activitietitle($uniacid, $id)
    {
        return $this->bigDb->activitietitle($uniacid, $id);
    }

    //ordersum
    public function ordersum($uniacid, $id)
    {
        return $this->bigDb->ordersum($uniacid, $id);
    }

    //countdown
    public function countdown($uniacid, $id)
    {
        return $this->bigDb->countdown($uniacid, $id);
    }

    //fullgourp 满团
    public function fullgourp($uniacid, $id)
    {
        return $this->bigDb->fullgourp($uniacid, $id);
    }

    //ui
    public function ui($uniacid, $id)
    {
        return $this->bigDb->ui($uniacid, $id);
    }

    public function ut($uniacid, $themeid)
    {
        return $this->bigDb->ut($uniacid, $themeid);
    }

    //payon
    public function payon($uniacid, $themeid)
    {
        return $this->bigDb->payon($uniacid, $themeid);
    }

    //newcus
    public function newoldcus($uniacid, $themeid, $newold)
    {
        return $this->bigDb->newoldcus($uniacid, $themeid, $newold);
    }

    //cusanking
    public function cusanking($uniacid, $themeid)
    {
        return $this->bigDb->cusanking($uniacid, $themeid);
    }

    public function worker($uniacid, $themeid)
    {
        return $this->bigDb->worker($uniacid, $themeid);
    }
    //fans
    public function fans($uniacid, $themeid)
    {
        return $this->bigDb->fans($uniacid, $themeid);
    }

    //15.员工业绩排行榜总人数
    public function workertop($uniacid, $themeid){

        return $this->bigDb->workertop($uniacid, $themeid);
    }

    //grouptop 16团队排行榜
    public function grouptop($uniacid, $themeid){

        return $this->bigDb->grouptop($uniacid, $themeid);
    }

    //redtop 17 红包排行
    public function redtop($uniacid, $themeid){
        return $this->bigDb->redtop($uniacid, $themeid);
    }

    //eventslist
    public function eventslist($uniacid, $themeid){
        return $this->bigDb->eventslist($uniacid, $themeid);
    }

    //findOrder
    public function findOrder($uniacid, $themeid,$openid ){
        return $this->bigDb->findOrder($uniacid, $themeid,$openid);
    }

    //findbysn
    public function findbysn($uniacid, $themeid,$openid ){
        return $this->bigDb->findbysn($uniacid, $themeid,$openid);
    }



    //findbyrr
    public function findbyrr($uniacid, $themeid,$openid ){
        return $this->bigDb->findbyrr($uniacid, $themeid,$openid);
    }

    //findbthemebyid
    public function findbthemebyid($themeid ){
        return $this->bigDb->findbthemebyid($themeid);
    }

    //testime
    public function testime($str){
        return $this->bigDb->testime($str);
    }

    //语言播报抓最新的10个订单 tentopOrder
    public function tentopOrder($uniacid, $themeid){
        return $this->bigDb->tentopOrder($uniacid, $themeid);
    }

    //yuyinone 一条
    public function yuyinone($uniacid, $themeid,$recordid){
        return $this->bigDb->yuyinone($uniacid, $themeid,$recordid);
    }

    //fetchpnames
    public function fetchpnames($pids){
        return $this->bigDb->fetchpnames($pids);
    }

    //findhaibao
    public function findhaibao_touxiang($uniacid,$themeid,$openid){
        return $this->bigDb->findhaibao_touxiang($uniacid,$themeid,$openid);
    }

    //活动东东都在里面 findhaibao_config
    public function findhaibao_config($uniacid,$themeid){
        return $this->bigDb->findhaibao_config($uniacid,$themeid);
    }

    public function findhaibao_config_t($themeid){
        return $this->bigDb->findhaibao_config_t($themeid);
    }

    //the_worklist
    public function the_worklist($uniacid,$themeid){
        return $this->bigDb->the_worklist($uniacid,$themeid);
    }

    //edit_work_by_openid
    public function edit_work_by_openid($uniacid,$themeid,$openid,$identity,$status){
        return $this->bigDb->edit_work_by_openid($uniacid,$themeid,$openid,$identity,$status);
    }

    //gettidby39like

    public function gettidby39like($key){
        return $this->bigDb->gettidby39like($key);
    }

    //phpabcoupons
    public function phpabcoupons($pid, $aid,$openid){
//
//        $num1 =  $this->bigDb->phpabc_buynum($pid, $aid,$openid);
//        $num2 =  $this->bigDb->phpabc_invitenum($pid, $aid,$openid);
//        $num3 =  $this->bigDb->phpabc_fansnum($pid, $aid,$openid);
        $num1 =  $this->bigDb->phpabc_buynum($pid, $aid,$openid);
        $num2 =  $this->bigDb->phpabc_invitenum($pid, $aid,$openid);
        $num3 =   $this->bigDb->phpabc_fansnum($pid, $aid,$openid);
        $a = array('num1'=>$num1,'num2'=>$num2,'num3'=>$num3,'sum'=>$num1+$num2+$num3);
        return $a;
    }

    //phpabcoupons_new
    public function phpabcoupons_new($pid, $aid,$openid,$newflagbuy,$newflaginvite){
        //todo 这里要写if else
        if($newflagbuy ==1){
            //todo
            LOG::info("fuwuA-1新版-翻卡牌入参$aid-$pid-$newflagbuy-$newflaginvite");
            $num1 =  $this->bigDb->phpabc_buynum_new($pid, $aid,$openid);
        }else{
            LOG::info("fuwuA-2新版-翻卡牌入参$aid-$pid-$newflagbuy-$newflaginvite");
            $num1 =  $this->bigDb->phpabc_buynum($pid, $aid,$openid);
        }

        if($newflaginvite ==1){
            LOG::info("fuwuB-1新版-翻卡牌入参$aid-$pid-$newflagbuy-$newflaginvite");
            $num2 =  $this->bigDb->phpabc_invitenum_new($pid, $aid,$openid);
        }else{
            LOG::info("fuwuB-2新版-翻卡牌入参$aid-$pid-$newflagbuy-$newflaginvite");
            $num2 =  $this->bigDb->phpabc_invitenum($pid, $aid,$openid);
        }


        $num3 =   $this->bigDb->phpabc_fansnum($pid, $aid,$openid);
        $a = array('num1'=>$num1,'num2'=>$num2,'num3'=>$num3,'sum'=>$num1+$num2+$num3);
        return $a;

    }




    //phpabcoupons_new  //大的

    //phpabc_buynum_notold_s
    public function phpabc_buynum_new_s($pid, $aid,$openid){
        $num1 =  $this->bigDb->phpabc_buynum_new($pid, $aid,$openid);
        return $num1;
    }

    //phpabc_invitenum_new
    public function phpabc_invitenum_new_s($pid, $aid,$openid){
        $num1 =  $this->bigDb->phpabc_invitenum_new($pid, $aid,$openid);
        return $num1;
    }



    //findOrderBytid2
    public function findOrderBytid2($tid2){
        return $this->bigDb->findOrderBytid2($tid2);
    }

    //findOrderBydetailid
    public function findOrderBydetailid($tid2){
        return $this->bigDb->findOrderBydetailid($tid2);
    }


    //findThemebyid
    public function findThemebyid($id){
        return $this->bigDb->findThemebyid($id);
    }



    //新业务 就是免费订单当时没有订单。前端让冬月给小陈多反了了个
    //findOrderByShortid
    public function findOrderByShortid($short){
        return $this->bigDb->findOrderByShortid($short);
    }



    //findRecordByxx
    public function findRecordByxx($xx){
        return $this->bigDb->findRecordByxx($xx);
    }

    //findRecordByNoid
    public function findRecordByNoid($noid){
        return $this->bigDb->findRecordByNoid($noid);
    }


    //findpidaidforfengbyphone
    public function findpidaidforfengbyphone_1($xx){
         return $this->bigDb->findpidaidforfengbyphone_1($xx);
    }

    //findaidsbyuid
    public function findaidsbyuid($uid,$cpage,$listrows){
        return $this->bigDb->findaidsbyuid($uid,$cpage,$listrows);
    }

    public function findpidaidforfengbyphone_2($xx){
        return $this->bigDb->findpidaidforfengbyphone_2($xx);
    }

    //findpidaidforfengbyaid
    public function findpidaidforfengbyaid($xx){
        return $this->bigDb->findpidaidforfengbyaid($xx);
    }


    public function findpidaidforfengbyphone_3($xx,$yy){
        return $this->bigDb->findpidaidforfengbyphone_3($xx,$yy);
    }

    //找一条活动记录  findphonebyaid
    public function findphonebyaid_1($xx){
        return $this->bigDb->findphonebyaid_1($xx);
    }

    //findphonebyaid_2  找用户
    public function findphonebyaid_2($xx){
        return $this->bigDb->findphonebyaid_2($xx);
    }

    //findchouuser
    public function findchouuser($pid,$arr){
        return $this->bigDb->findchouuser($pid,$arr);
    }

    //getapp
    public function getapp(){
        return $this->bigDb->getapp();
    }
    //getwechats

    public function getwechats(){
        return $this->bigDb->getwechats();
    }

    //getappbypid
    public function getappbypid($pid){
        return $this->bigDb->getappbypid($pid);
    }

    //findpaymsgbypid
    public function findpaymsgbypid($pid){
        return $this->bigDb->findpaymsgbypid($pid);
    }

    //findaidsbypid
    public function findaidsbypid($pid){
        return $this->bigDb->findaidsbypid($pid);
    }


    //pcaids_totalfee
    //record的 收款
    public function pcaids_totalfee($pid){
        return $this->bigDb->pcaids_totalfee($pid);
    }

    //pcaids_commfee
    public function pcaids_commfee($pid){
        return $this->bigDb->pcaids_commfee($pid);
    }

    //pcaids_other
    public function pcaids_other($pid){
        return $this->bigDb->pcaids_other($pid);
    }

    //findcasebypid
    public function findcasebypid($pid){
        return $this->bigDb->findcasebypid($pid);
    }

    //findformsetbypidandaid
    public function findformsetbypidandaid($pid,$aid){
        return $this->bigDb->findformsetbypidandaid($pid,$aid);
    }

    //findthemeinfobypidaid
    public function findthemeinfobypidaid($pid,$aid){
        return $this->bigDb->findthemeinfobypidaid($pid,$aid);
    }

    //findconfigbypidaid
    public function findconfigbypidaid($pid,$aid){
        return $this->bigDb->findconfigbypidaid($pid,$aid);
    }

    //pcfindordernum
    public function pcfindordernum($lgdate){
        return $this->bigDb->pcfindordernum($lgdate);
    }

    //pcfindordernum
    public function pcfindgroup($pid,$aid){
        return $this->bigDb->pcfindgroup($pid,$aid);
    }

    //xiav1
    public function xiav1($id){
        return $this->bigDb->xiav1($id);
    }

    //find_orders_bypidaid
    public function find_orders_bypidaid($pid,$aid){
        return $this->bigDb->find_orders_bypidaid($pid,$aid);
    }

    //findobj_forfix  老订单号; 找交易对象 其实为了那个 42开头的tid2
    public function findobj_forfix($oid){
        return $this->bigDb->findobj_forfix($oid);
    }


    //获取pids 或者叫unicaids_  一个账号（手机号->uid ）做过的活动 didpid
    public function finddidpid_byphone($phone)
    {
        return $this->bigDb->finddidpid_byphone($phone);
    }

    //find_f_name
    public function find_f_name($uniacid,$themeid,$openid)
    {
        return $this->bigDb->find_f_name($uniacid,$themeid,$openid);
    }

    //findrecordsbykey
    public function findrecordsbykey($pid,$aid,$key)
    {
        return $this->bigDb->findrecordsbykey($pid,$aid,$key);
    }
}
